package com.ad.services;

import java.util.Calendar;
import java.util.List;

import com.ad.dao.ITipDao;
import com.ad.dao.ITipTypeDao;
import com.ad.hibernate.Tip;
import com.ad.hibernate.TipType;
import com.ad.hibernate.TipView;

public class TipManagerService implements ITipManagerService {

	private ITipDao tipDao;

	private ITipTypeDao tipTypeDao;

	@Override
	public List<Tip> findTips() {
		List<Tip> tipList = this.getTipDao().findTips();
		return tipList;
	}

	public ITipDao getTipDao() {
		return tipDao;
	}

	public void setTipDao(ITipDao tipdao) {
		this.tipDao = tipdao;
	}

	@Override
	public void delete(TipType tipType) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<TipType> getChildren(String id) {
		return this.tipTypeDao.getChildren(id);
	}

	@Override
	public List<TipType> getType() {
		return this.tipTypeDao.getType();
	}

	@Override
	public String insert(TipType tipType) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void update(TipType tipType) {
		// TODO Auto-generated method stub

	}

	public void setTipTypeDao(ITipTypeDao tipTypeDao) {
		this.tipTypeDao = tipTypeDao;
	}

	public ITipTypeDao getTipTypeDao() {
		return tipTypeDao;
	}

	@Override
	public void insert(Tip tip) {
		if (tip != null) {
			Calendar c = Calendar.getInstance();
			tip.setCreateDate(c.getTime());
			long time = c.getTimeInMillis();
			c.setTimeInMillis(time + 7 * 24 * 60 * 60 * 1000);
			tip.setEndDate(c.getTime());
			this.tipDao.insert(tip);
		}
	}

	@Override
	public List<TipView> findTipViews() {
		List<TipView> tipList = this.getTipDao().findTipViews();
		return tipList;
	}

}
